package com.course.controller;

import com.course.pojo.Courses;
import com.course.service.CoursesService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class CoursesController {

    private CoursesService coursesService;

    @RequestMapping(value = "coursesinfo",method = RequestMethod.POST)
    @ResponseBody
    @PostMapping("/coursesinfo")
    public String addCourses(String coursesid){
        try {
            boolean t = coursesService.is_account(account);
            if(t){
                coursesService.addCourses(coursesid);
                json.put("meg","添加成功");
                json.put("code","200");
            } else{
                json.put("meg","天剑失败");
                json.put("code","-1");
            }
        } catch (Exception e) {
            e.printStackTrace();
            json.put("meg","添加失败");
            json.put("code","-1");
        }
        return json.toJSONString();
    }

    public String deleteCourses(String coursesid){
        try{
            boolean a = coursesService.is_account(account);
            if(a){
                coursesService.deleteCourses(coursesid);
                json.put("meg","删除成功");
                json.put("code","200");
            } else{
                json.put("meg","删除失败");
                json.put("code","-1");
            }

        }catch(Exception e){
            e.printStackTrace();
            json.put("meg","删除失败");
            json.put("code","-1");
        }
    }

}